import { PrismaService } from '../../common/modules/prisma/prisma.service'
import { ConfigService } from '@nestjs/config'
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from 'passport-jwt'

@Injectable()
export class JwtStartegy extends PassportStrategy(Strategy, 'jwt') {
  constructor(ConfigService: ConfigService, private prisma: PrismaService) {
    super({
      // 解析用户提交的Bearer Token headers 数据
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      // 加密用的secret
      secretOrKey: ConfigService.get('TOKEN_SECRET_KEY'),
    })
  }
  // 对token解析后是否再次验证
  async validate(data) {
    return data
  }
}
